package snippets;

/*
 * Table example snippet: create a table with column header images
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import task.ConnectionDescription;

public class Snippet297Table {

	public static void main (String [] args) {
		Display display = new Display ();
		Shell shell = new Shell (display);
		shell.setLayout(new GridLayout());

		createTable(shell, display, null);
		
		shell.pack ();
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
	public static Table createTable(Composite parent, Display display, ConnectionDescription[] conns) 
	{
//		Image images[] = new Image[] {
//				display.getSystemImage(SWT.ICON_INFORMATION),
//				display.getSystemImage(SWT.ICON_ERROR),
//				display.getSystemImage(SWT.ICON_QUESTION),
//				display.getSystemImage(SWT.ICON_WARNING),
//			};
		String[] titles = {"Name", "URL", "User", "Password"};
		String[] questions = {"who?", "what?", "where?", "when?", "why?"};
		Table table = new Table (parent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
		GridData data = new GridData (SWT.FILL, SWT.FILL, true, true);
		data.heightHint = 200;
		table.setLayoutData (data);
		table.setLinesVisible (true);
		table.setHeaderVisible (true);
		for (int i=0; i<titles.length; i++) {
			TableColumn column = new TableColumn (table, SWT.NONE);
			column.setText (titles [i]);
//			column.setImage(images [i]);
		}	
		int count = 12;
		for (ConnectionDescription conn : conns) {
			TableItem item = new TableItem (table, SWT.NONE);
			item.setText (1, conn.getUrl());
			item.setText (0, conn.getName());
			item.setText (2, conn.getUser());
			item.setText (3, conn.getPasswd());
		}
		for (int i=0; i<titles.length; i++) {
			table.getColumn (i).pack ();
		}	
		return table;
	}
} 
